//
//  PersonCenterViewController.m
//  qdSubway
//
//  Created by andi911 on 2019/5/29.
//  Copyright © 2019 andi911. All rights reserved.
//

#import "PersonCenterViewController.h"
#import "FXCustomizeButton.h"
#import "TaskCenterViewController.h"
#import "PersonCenterViewController.h"
#import "QDDutyInspectorApplyViewController.h"

@interface PersonCenterViewController ()

@end

@implementation PersonCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"个人中心";
    self.view.backgroundColor = RGB(247);
    [self setupUI];
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
    [button addTarget:self action:@selector(gotoApplyVc) forControlEvents:1<<6];
    [button setTitle:@"义务监督员" forState:0];
    [button setTitleColor:[UIColor blackColor] forState:0];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
}

- (void)gotoApplyVc{
    QDDutyInspectorApplyViewController *vc = [[QDDutyInspectorApplyViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)setupUI{
    UIView *totalView = [[UIView alloc]init];
    totalView.backgroundColor = [UIColor whiteColor];
    totalView.width = Screen_W;
    totalView.height = 100;
    [self.view addSubview:totalView];
    
    UIImageView *headImage = [[UIImageView alloc]init];
    headImage.width = 80;
    headImage.height = 80;
    headImage.backgroundColor = [UIColor grayColor];
//    headImage.image = CLYImage(@"carUser");
    headImage.center = CGPointMake(20+headImage.width/2, getRectNavAndStatusHight+20+headImage.height/2);
    headImage.layer.cornerRadius = headImage.width/2;
    headImage.layer.masksToBounds = YES;
    [totalView  addSubview:headImage];
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.text = @"我是安迪911";
    nameLabel.width = Screen_W -headImage.right-25-15;
    nameLabel.height = 18;
    nameLabel.center = CGPointMake(headImage.right+15+nameLabel.width/2, headImage.centerY-5-nameLabel.height/2);
    [totalView addSubview:nameLabel];
    
    UILabel *integralLabel = [[UILabel alloc]init];
    integralLabel.text = @"积分: 1000";
    integralLabel.width = Screen_W -headImage.right-25-15;
    integralLabel.height = 16;
    integralLabel.font = CLYFont(14);
    integralLabel.center = CGPointMake(headImage.right+15+integralLabel.width/2, headImage.centerY+5+integralLabel.height/2);
    [totalView addSubview:integralLabel];
    
    UIButton *centerBtn = [[UIButton alloc]init];
    centerBtn.width = Screen_W;
    centerBtn.height = 120;
    centerBtn.center = CGPointMake(Screen_W/2, getRectNavAndStatusHight+125+centerBtn.height/2);
    centerBtn.backgroundColor = [UIColor lightGrayColor];
//    centerBtn.titleLabel.text = @"点击前往任务中心";
    [centerBtn setTitle:@"点击前往任务中心" forState:UIControlStateNormal];
    [centerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [centerBtn addTarget:self action:@selector(tapCenterBtn) forControlEvents:1<<6];
    [totalView addSubview:centerBtn];
    
    UIImageView *leftImage = [[UIImageView alloc]initWithImage:CLYImage(@"left_panddIma")];
    leftImage.center = CGPointMake(leftImage.width/2, centerBtn.bottom+35);
    [totalView addSubview:leftImage];
    
    UIButton *mytaskBtn = [[UIButton alloc]init];
    mytaskBtn.width = Screen_W-40;
    mytaskBtn.height = 44;
    mytaskBtn.center = CGPointMake(20+mytaskBtn.width/2, leftImage.centerY);
    [mytaskBtn setTitle:@"我的任务" forState:UIControlStateNormal];
    mytaskBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    mytaskBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, mytaskBtn.width-75);
//    [mytaskBtn.titleLabel setTextAlignment:2];
//    mytaskBtn.backgroundColor = [UIColor blackColor];
    [mytaskBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [mytaskBtn addTarget:self action:@selector(tapmytaskBtn) forControlEvents:1<<6];
    [totalView addSubview:mytaskBtn];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20, mytaskBtn.bottom+15, Screen_W-40, 0.5)];
    line.backgroundColor = [UIColor lightGrayColor];
    [totalView addSubview:line];
    
    CGFloat space = (Screen_W - 3*50)/4.0;
    NSArray *titleArr = @[@"待完成",@"已完成",@"已结束"];
    NSArray *imageArr = @[@"predone",@"haveDone",@"haveFinshed"];
    NSArray *numberArr = @[@"1",@"2",@"3"];
    
    for (int i =0; i<3; i++) {
        FXCustomizeButton *btn =[FXCustomizeButton buttonWithImagePosition:ImagePositionTop innerPadding:5];
        btn.width = 50;
        btn.height = 75;
        btn.center = CGPointMake(space+btn.width/2+(btn.width+space)*i, line.bottom+15+btn.height/2);
//        btn.backgroundColor = [UIColor lightGrayColor];
        btn.tag = 10+i;
        btn.titleLabel.font = CLYFont(16);
        [btn setTitle:titleArr[i] forState:0];
        [btn setImage:CLYImage(imageArr[i]) forState:0];
        [btn setTitleColor:[UIColor blackColor] forState:0];
        [btn addTarget:self action:@selector(tapBtn:) forControlEvents:1<<6];
        [totalView addSubview:btn];
        
        UILabel *titleLab = [[UILabel alloc]init];
        titleLab.width = btn.width;
        titleLab.height = 16;
        titleLab.textAlignment = NSTextAlignmentCenter;
        titleLab.text = numberArr[i];
        titleLab.font = CLYFont(16);
        titleLab.center = CGPointMake(btn.centerX, btn.bottom+titleLab.height/2);
        [totalView addSubview:titleLab];
        if (i==2){
            totalView.height = titleLab.bottom+25;
        }
        
    }

}

#pragma mark --- 点击事件 ----

- (void)tapCenterBtn{
    TaskCenterViewController *vc = [[TaskCenterViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)showAlertView:(NSString *)str{
    if(!str.length){
        str = @"测试";
    }
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:str preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)tapmytaskBtn{
    TaskCenterViewController *vc = [[TaskCenterViewController alloc]init];
    vc.status = 1;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)tapBtn:(UIButton *)sender{
    TaskCenterViewController *vc = [[TaskCenterViewController alloc]init];
    vc.status = (int)sender.tag;
    [self.navigationController pushViewController:vc animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
